package com.zusmart.core.config.source;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.zusmart.core.config.ConfigSource;
import com.zusmart.core.config.support.AbstractConfigSourceConverter;

public class ConfigSourceConverterForXml extends AbstractConfigSourceConverter {

	@Override
	public String getSupportExtension() {
		return ConfigSourceForXml.EXTENSION;
	}

	@Override
	protected ConfigSource doConvert(InputStream inputStream, String fileName) throws Exception {
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document document = builder.parse(inputStream);
		Element element = document.getDocumentElement();
		return new ConfigSourceForXml(fileName, element);
	}

}